
import Editor from './editor'
import withUpperCase from "./plugins/to_upper_case";
import withLogger from "./plugins/logger";
import WithUndoRedo from "./plugins/undo_redo/index";

window.onload = () => {
    const container = document.getElementById('container-pre')
    if (container) {
        const editor = WithUndoRedo(new Editor(container))
        // const editor = new WithUndoRedo(editor)
        editor.init()
    }
}

// let spacers = ''
// let anchor = 0
// window.onload = () => {
//     const viewContainer: any = document.getElementById('container');
//     viewContainer.addEventListener('beforeinput', (e: any) => {

//         const inputType = e.inputType
//         e.preventDefault();
//         if (inputType === 'insertText') {
//             const text = e.data
//             const oldSpacers = spacers;
//             if (text) {
//                 spacers = oldSpacers.slice(0, anchor) + text + oldSpacers.slice(anchor)
//                 viewContainer.innerHTML = spacers
//                 anchor += text.length
//                 const domSelection = window.getSelection()
//                 if (domSelection) {
//                     const range = window.document.createRange()
//                     console.log(range);
//                     range.setStart(viewContainer.childNodes[0], anchor)
//                     range.setEnd(viewContainer.childNodes[0], anchor)
//                     domSelection.removeAllRanges()
//                     domSelection.addRange(range)
//                 }

//             }
//         }
//     })
// }